package com.itheima.xinxi.system.service;

import com.itheima.xinxi.system.dao.TeacherDao;
import com.itheima.xinxi.system.domain.Student;
import com.itheima.xinxi.system.domain.Teacher;

public class TeacherService {
    private TeacherDao dao=new TeacherDao();

    //增
    public  void addTeacher(Teacher teacher){

        dao.addTeacher(teacher);
    }
    //删
    public void deleteTeacherById(String id){
        dao.deleteTeacherById(id);
    }
    //改
    public void updateTeacher(String id, Teacher teacher){
        dao.updateTeacher(id,teacher);
    }
    //查
    public Teacher[] findAll(){
        Teacher[] teachers = dao.findAll();
        for (int i = 0; i < teachers.length; i++) {
            if(teachers[i]!=null){
                return teachers;
            }
        }
        return null;

    }
    //判断id 是否存在
    public boolean panduan(String id){
        Teacher[] teachers = dao.findAll();
        for (int i = 0; i < teachers.length; i++) {
            if(teachers[i]!=null&&teachers[i].getId().equals(id)){
                return true;
            }
        }
        return false;
    }

}
